//统一管理的接口
import http from "./http";

let login = (params) => http.post('/login',params)   //登录接口

let menus = (params) => http.get('/menus',params)   //侧边栏接口

let users = (params) => http.get('/users',{params})  //用户列表页面接口

let add = (params) => http.post('/users',params)     //用户列表添加接口

let del = (params) => http.delete(`/users/${params.id}`,params)  //用户列表删除接口

let edit = (id,params) => http.put(`/users/${id}`,params)   //用户列表编辑接口

let rights = (params) => http.get('/rights/list',{params})  //权限列表接口

let rightsTree = () => http.get('/rights/tree')  //权限回填接口

let rightsOK = (roleId,params) => http.post(`roles/${roleId}/rights`,params)  //权限修改接口

let goods = (params) => http.get('/goods',{params})         //商品列表页面接口

let goodDel = (params) => http.delete(`/goods/${params.goods_id}`,params)  //商品列表删除

let goodAdd = (params) => http.post('/goods',params)   //商品列表添加接口

let goodEdit = (params) => http.put(`/goods/${params.goods_id}`,params)  //商品列表编辑接口

let goodImg = (params) => http.post('/upload',params)  //商品列表编辑接口

let getRole = (params) => http.get('/roles',params)   //角色权限数据

let rolesAdd = (params) => http.post('/roles',params) //角色添加数据

let rolesDel = (params) => http.delete(`/roles/${params.id}`,params)   //角色删除

let rolesEdit = (id,params) => http.put(`/roles/${id}`,params)   //角色编辑

let rolesRight = (row,rightId) => http.delete(`/roles/${row.id}/rights/${rightId}`)   //删除角色列表下面的权限

let report = (params) => http.get('/reports/type/1',params)   //树状图接口

let orders = (params) => http.get('/orders',{params})  //订单管理页面接口

let goodF  = (params) => http.get('/categories',{params}) //商品分类数据接口

let DIZHI  = (params) => http.get('/categories',params) //商品分类数据接口

let GoodParamsList  = (params) => http.get(`/categories`,{params}) //商品参数列表

let GoodList  = (params) => http.get(`/categories/${params.id}/attributes?sel=${params.sel}`,params) //商品参数数据

let ParamDel  = (id,attrid) => http.delete(`/categories/${id}/attributes/${attrid}`) //商品参数删除

// let ParamsAdd  = (params) => http.post(`/categories/${params.id}/attributes?attr_name=${params.attr_name}&attr_sel=${params.attr_sel}/`) //商品参数删除
async function ParamsAdd(params){
    let {data} = await http.post(`/categories/${params.id}/attributes/?attr_name=${params.attr_name}&attr_sel=${params.attr_sel}`,params)
    return data
}

async function EditParams(params){
    let {data} = await http.put(`/categories/${params.id}/attributes/${params.attrId}?attr_name=${params.attr_name}&attr_sel=${params.attr_sel}`,params)
    return data
}

async function ParamsAddEdit(params){
    let {data} = await http.post(`/categories/${params.id}/attributes/${params.attrId}?attr_name=${params.attr_name}&attr_sel=${params.attr_sel}&attr_vals=${params.attr_vals}`,params)
    return data
}

// let EditParams  = (params) => http.put(`/categories/${params.id}/attributes/${params.attrId}?attr_name=${params.attr_name}&attr_sel=${params.attr_sel}`) //商品参数编辑
 
export {login,users,add,del,edit,rights,goods,goodDel,

    goodAdd,getRole,rolesAdd,rolesDel,rolesEdit,report,

    goodEdit,orders,menus,goodF,rolesRight,rightsTree,
    
    rightsOK,goodImg,DIZHI,GoodParamsList,GoodList,ParamDel,EditParams,ParamsAdd,ParamsAddEdit}

// const login = 